<template>
	
	<view class="uni-tab-bar">
		<view class="uni-swiper-tab">
				<view v-for="(tab,index) in tabBars" :key="tab.id" class="swiper-tab-list" :class="tabIndex==index ? 'active' : ''" :id="tab.id"
			 :data-current="index" @click="tapTab">{{tab.name}}</view>
		</view>
		<view class="content">
					<view class="skxi" v-if="flag1">
				<view class="con">
					<image src="../../../static/images/icon/jingtan.png"></image>
					<view class="tip">
						<view>没收到款千万不要确认</view>
						<view>造成损失自己负责</view>
					</view>
					<view class="jine">
						<input type="number" v-model="amount" placeholder="输入收款金额" />
					</view>
					<view class="confim">
			
						<view @click="quxiao">取消</view>
						<view class="blue" @tap="tijiao">确定</view>
					</view>
				</view>
			</view>
				<swiper :current="tabIndex" class="swiper-box" :duration="300" @change="changeTab">
			<swiper-item >
				<all :current="tabIndex"></all>
			</swiper-item>
				<swiper-item >
				<wancheng :current="tabIndex"></wancheng>
			</swiper-item>
			<swiper-item >
				<chaoshi :current="tabIndex"></chaoshi>
			</swiper-item>
			</swiper>
		</view>
	
	</view>
</template>
<script>

import all from '@/component/lsdingdan/all/index.vue';
import wancheng from '@/component/lsdingdan/wancheng/index.vue';
import chaoshi from '@/component/lsdingdan/chaoshi/index.vue';
  export default {
		data() {
			return {
				flag1: false,
				account: '',
				amount: '',
				type:'',
				scrollLeft: 0,
				isClickChange: false,
				tabIndex: 0,
				newsitems: [],
				showflag:false,
				tabBars: [ {
					name: '全部',
					id: 'jie'
				},{
					name: '已完成',
					id: 'wancheng'
				},
				{
					name: '已超时',
					id: 'chaoshi'
				}
				]
			}
		},
		components: {
			
			all,
		
			wancheng,
			chaoshi
			
		},
		onLoad() {
	var data = {
		token: uni.getStorageSync('token'),
		type:0
	};
	this.$store.dispatch('alldingdan', data);
		},
		mounted(){
		this.$bus.$on('shoun', data => {
		console.log(data)
		this.flag1 = data.flag;
		this.account = data.account;
		this.type = data.type;
		
	});
		},
		onShow(){
		
				  try {
					      const value = uni.getStorageSync('tab_key');
					      if (value) {
							  if(value==true){
								  console.log(this.tabIndex)
								 this.tabIndex = 2; 
							  }
					          console.log(value);
					      }
					  } catch (e) {
					      
					  }
					  uni.removeStorage({
			    key: 'tab_key',
			    success: function (res) {
			        
			    }
			});
		
		},
		methods: {
			quxiao(){
				this.flag1 = false;
				this.amount ="";
				
			},
				tijiao() {
				if (this.amount) {
					var data = {
						token: uni.getStorageSync('token'),
						order_id:this.account.order_id,
						order_amount:this.amount
					}
					this.$store.dispatch('confirmreceitp', data)
					.then(res=>{
						this.amount = "";
						uni.showToast({
							title: res.data.msg,
							icon: "none"
						})
						if(res.data.code==1){
							if(this.type=='all'){
								this.$bus.$emit("allorder",1)
							}
							else if(this.type=="chaoshi"){
								this.$bus.$emit("csorder",1)
							}
							// var data = {
							// 	token: uni.getStorageSync('token'),
							// };
							// this.$store.dispatch('orderunderway', data)
							this.flag1 = false;
						}
					})
				}
				else{
					uni.showToast({
						title: '请输入收款金额',
						icon: "none"
					})
				}
			},
			 changeTab(e) {
				let index = e.target.current;
				if (this.isClickChange) {
					this.tabIndex = index;
					this.isClickChange = false;
					return;
				}			
				this.isClickChange = false;
				this.tabIndex = index; //一旦访问data就会出问题
			},
		
			 tapTab(e) { //点击tab-bar
				let tabIndex = e.target.dataset.current;
				if (this.tabIndex === tabIndex) {
					return false;
				} else {
					this.isClickChange = true;
					this.tabIndex = tabIndex;
				}
			},
		
		}
	}
</script>
<style lang="scss" scoped src="./index.scss"></style>